﻿#region Imports
using System;
#endregion

namespace CommonUtilities.Attributes
{
    /// <summary>
    /// Specifies that the property is sortable
    /// </summary>
    [AttributeUsage(AttributeTargets.Property, Inherited = false, AllowMultiple = false)]
    public sealed class SortableAttribute : Attribute
    {
        #region Declaration
        /// <summary>
        /// Default value for IsSortable property
        /// </summary>
        private const bool defaultSortable = true;

        /// <summary>
        /// Default property name
        /// </summary>
        public static readonly string DefaultPropertyName = "IsSortable";

        /// <summary>
        /// Specifies the default instance for the <code>CommonUtilities.Attributes.SortableAttribute</code>
        /// </summary>
        public static readonly SortableAttribute Default = new SortableAttribute() { IsSortable = defaultSortable };

        /// <summary>
        /// Specifies the default value for the <code>CommonUtilities.Attributes.SortableAttribute.IsSortable</code> when property not attributed to
        /// </summary>
        public static readonly bool DefaultValueOnAbsent = !Default.IsSortable;
        #endregion

        #region Properties
        /// <summary>
        /// Specifies if property is sortable
        /// </summary>
        public bool IsSortable { get; private set; }
        #endregion

        #region Constructors
        /// <summary>
        /// Initializes a new default instance of <code>CommonUtilities.Attributes.SortableAttribute</code>
        /// </summary>
        public SortableAttribute()
            : base()
        {
            IsSortable = defaultSortable;
        }
        #endregion

        #region Methods
        public override bool Equals(object obj)
        {
            return this.IsSortable == ((SortableAttribute)obj).IsSortable;
        }

        /// <summary>
        /// Determines if this attribute is the default instance
        /// </summary>
        /// <returns>TRUE if the attribute is the default instance for this attribute class;
        /// <para>otherwise, FALSE</para></returns>
        public override bool IsDefaultAttribute()
        {
            return this.IsSortable == Default.IsSortable;
        }
        #endregion
    }
}
